package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2024/9/24 09:14
 * @apiNote
 */

public class Test02207MaximumSubsequenceCount {
    public static void main(String[] args) {
        String text = "abdcdbc";
        String pattern = "ac";
        System.out.println(maximumSubsequenceCount(text, pattern));
    }
    public static long maximumSubsequenceCount(String text, String pattern) {
        long res = 0;
        int cnt1 = 0,cnt2 = 0;
        for(int i = 0; i< text.length(); i++) {
            if(text.charAt(i) == pattern.charAt(1)){
                res += cnt1;
                cnt2++;
            }
            if(text.charAt(i) == pattern.charAt(0)){
                cnt1++;
            }
        }
        return res+ + Math.max(cnt1,cnt2);
    }
}
